#include "../inc/CpnCaptureInterface.h"


#include "highgui.h"	//CvCapture
#include <cvcam.h>	//cvcamGetCamerasCount
#include <iostream>

#if _DEBUG
#include "../inc/CommonPrefVar.h"
#endif

CpnCaptureInterface::CpnCaptureInterface()
:m_capture(NULL)
{
}

CpnCaptureInterface::~CpnCaptureInterface()
{
	cvReleaseCapture( &m_capture );
}

int CpnCaptureInterface::GetCamCount()
{
	return cvcamGetCamerasCount();
}

void CpnCaptureInterface::InitCam(int Num)
{
	if(cvcamGetCamerasCount()==0)
		throw std::exception("Do have a connected camera!",0);

	m_capture = cvCaptureFromCAM(Num);
	if(m_capture == NULL)
		throw std::exception("Can't have a handle over the desired camera");
};

IplImage* CpnCaptureInterface::getMostRecentFrame()
{
	assert("The camera is not connected" && m_capture!=NULL);
#if _DEBUG
	IplImage* test = cvQueryFrame(m_capture);
	cvSaveImage(_Preferences::DEBUG_DIR.c_str(), test);
	return test;
#else
	return cvQueryFrame(m_capture);
#endif
}